#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int d[N], s[N],t[N];
int f[N], r[N];
int n, m; 
bool check(int x)
{
	for(int i = 1; i <= n; i++) f[i] = r[i] - r[i-1];
	for(int i = 1; i <= x; i++)
	{
		int d1 = d[i],s1 = s[i], t1 = t[i];
		f[s1] -= d1, f[t1 + 1] += d1; 
	}
	for(int i = 1; i <= n; i++)
	{
		f[i] += f[i-1];
		if(f[i] < 0) return false;
	}
	return true;
}

int main() 
{
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) cin >> r[i];

	for(int i = 1; i <= m; i++) cin >> d[i] >> s[i] >> t[i];
	
	int l = 1, r = m;
	
	while(l < r)
	{
		int mid = (l + r) / 2;
		if(check(mid)) l = mid + 1;
		else r = mid;
	}
	
	if(check(l)) cout << 0 << endl;
	else cout << -1 << endl << l << endl;
	return 0; 
}
